package softserve.vgolosh;

import java.io.File;
import java.util.List;
import java.util.Scanner;

import softserve.vgolosh.utils.CmdUtil;
import softserve.vgolosh.utils.FileUtil;
import softserve.vgolosh.utils.PropertiesHelper;
import softserve.vgolosh.utils.PropertyNotFoundException;

public class MainClass {
	public static String MOZILLA_LOCATION = "C:\\Program Files\\Mozilla Firefox_3\\";
	static {
		if (PropertiesHelper.isInitialised()) {
			try {
				MOZILLA_LOCATION = PropertiesHelper.getProperty("MOZILLA_PATH");
			} catch (PropertyNotFoundException e) {
				System.out.println(e);
				System.out.println("using default value " + MOZILLA_LOCATION);
			}
		}
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		List<String> tickets = FileUtil.getTicketCommands("allClients.csv");
		openTicketsInFirefox(tickets);
		scanner.nextLine();
	}

	private static void openTicketsInFirefox(List<String> tickets) {
		String[] commands = null;
		File dir = new File(MOZILLA_LOCATION);
		for (String ticket : tickets) {
			commands = new String[] { "cmd.exe", "/c", "firefox.exe " + ticket };
			CmdUtil.startCommand(commands, dir);
		}
	}
}
